#!/usr/bin/env python2
# ----------------------------------------------------------------------------
# SITE-SPECIFIC CONFIGURATION

CALLSIGN = "VK2CJB-6"
QRPBBBHOME = "/root/qrpbbb"

# Freeform, but callsign,name,qth,gratuitous qrpbbb promotion,email is good.
# Try to keep it under 160 chars, though.
IDENT = "This station is operated by Chris VK2CJB, from Ellalong NSW (QF57pc)," \
" using QRPBBB 20210421, a distributed BBS. Email vk2cjb@gmail.com for off-air enquiries."

# How the system should treat the frequency the radio is on.
# qrpbbb: 'strict qrpbbb'-- when using the APRS digipeater mesh: small message size
#   limits, slow packet tx clock, one packet transmitted at a time.
# radio: 'generous qrpbbb'-- when using an exclusive frequency (147.550?)
#   more generous message sizes, multiple packets at once, generous packet tx clock.
#   Still usually 1200 baud, though. Maybe good for 1MB/day in messages.
# fastradio: like radio, except 9600 baud and above: Claude Shannon has the final say.
#
# If you are not going to be apart of the QRPBBB network that VK2CJB is
# creating, with its mandated conditions for best-practice message content,
# news site soundness, and not trashing the APRS digipeater network, you must
# use different distributions from "qrpbbb", "radio", and "fastradio". This
# is also to keep regular Usenet articles leaking into the network if your
# newsserver handles other newsgroups.

RADIOMODE = "aprs"

# MAXMSGLEN - limit for the number of lines in the body of a message.
# MAXMSGSIZ - limit in bytes for a message.
# PCKATTIME - how many packets to send during an over.
# WANTMINAGE - wait in minutes from a message being updated before requesting lines.
# TXCLOCK - seconds between packet tx, aligned to the system clock.
# TXSLOT - ALOHANet-esque slot into the transmission period, different to other sites.
# You think the 21st Century should have nice long descriptive camelCase labels? Too bad!

LIMITS = {
    "aprs": {"MAXMSGLEN": 100, "MAXMSGSIZ": 8192, "PCKATTIME": 1,
             "TXCLOCK": 60, "TXSLOT": 0, "WANTMINAGE": 10},
    "simplex": {"MAXMSGLEN": 1000, "MAXMSGSIZ": 100000, "PCKATTIME": 1,
                "TXCLOCK": 30, "TXSLOT": 0, "WANTMINAGE": 5},
    "fast": {"MAXMSGLEN": 10000, "MAXMSGSIZ": 1000000, "PCKATTIME": 100,
             "TXCLOCK": 30, "TXSLOT": 0, "WANTMINAGE": 1}
}
LIMITS["qrpbbb"] = LIMITS["aprs"]
LIMITS["radio"] = LIMITS["simplex"]
LIMITS["fastradio"] = LIMITS["fast"]

DISTROSIMPLEX = ""              # Simplex use
DISTROAPRS = ",WIDE1-1,RFONLY"  # Local digipeater range
DISTROMAX = ",WIDE1-1,WIDE2-1" # As far as possible... (used for beacon)
DISTROHIM = ",VK2RTZ-1,VK2RAG-1,RFONLY" # Directed at someone. Learn2PHG

if RADIOMODE == "aprs":
    ACCEPTDISTRO = ["qrpbbb"]
    DISTRO = DISTROAPRS

if RADIOMODE == "simplex":
    ACCEPTDISTRO = ["qrpbbb", "radio"]
    DISTRO = DISTROSIMPLEX

if RADIOMODE == "fast":
    ACCEPTDISTRO = ["qrpbbb", "radio", "fastradio"]
    DISTRO = DISTROSIMPLEX

APPDEST = "APZQRP"
APRSPREAM = CALLSIGN + ">" + APPDEST + DISTRO + ":{{Q"
MAXPREAMB = CALLSIGN + ">" + APPDEST + DISTROMAX + ":{{Q"
APRSANN = CALLSIGN + ">" + APPDEST + DISTROMAX + ":!3256.11S/15119.26EBSpam Alert: I'm Testing QRPBBB"

NEWSSPOOL = "/var/spool/news"
KISS_IN = "/var/spool/packet/recv"
KISS_OUT = "/var/spool/packet/send"
INEWS = "/usr/bin/inews"
import os
POSTLOG = os.path.join (QRPBBBHOME, "Received")
BADLIST = os.path.join (QRPBBBHOME, "BadMsgids")
QUEUE_IN = os.path.join (QRPBBBHOME, "queue/incoming")
QUEUE_OUT = os.path.join (QRPBBBHOME, "queue/outgoing")
STATIONLOG = os.path.join (QRPBBBHOME, "Stations")

QUEUE_TOOOLD = 14               # in days
MISSINGLINE = "__ __ __ __ __"

# That's my old callsign.. just until real bozos show up.
BADCALLS = ["VK2FJDA"]
# Really a feature for radio/fastradio stations that don't want "binary" newsgroups.
BADGROUPS = ["reddit.*", "facebook.*", "phpbb.*", "twitter.*"]

#
# ----------------------------------------------------------------------------
#

# todo: Have this file (fully!) verify the site configuration if executed.
# No, this isn't complete.

if __name__ == "__main__":
    NEWSCONFIG = "/etc/news"

    filetests = [
        { "QRPBBBHOME", os.path.join(QRPBBBHOME, "site_config.py"), "touchtest"},
        { "NEWSSPOOL", os.path.join(NEWSSPOOL, "in.coming"), "newsowner"}
    ]

    # check NEWSCONFIG/newsfeeds exists
    # check scrub in newsfeeds
    # check access permissions for news to _scrub.py
    # check KISS_ dirs exist and writable
    # inews file exists
    # check QUEUE_IN/OUT exist and writable
    # check CALLSIGN

    # restart/reload INN and verify the _scrub process exists..
    # ..if it's missing it's mostlikely a file permissions issue

    print "\nQRPBBB Configuration testing..."

    print """\nNow post a test message that doesn't violate the quality mandate.
Run ./qrpbbb_validate.py to find out its path in the newsspool and check the file has
been scrubbed with a X-QRPBBB: line added."""
    print "Hit Enter when done:",
    raw_input()

    print """\nPost a test message that is crossposted to multiple newsgroups.
Check your mailspool for the automatic email response from _scrub."""
    print "Hit Enter when done:",
    raw_input()

    print "\nRun ./qrpbbb_ihave.py and check for the creation of a packet in queue/outgoing/"
    print "Hit Enter when done:",
    raw_input()

    print """\nStart up ./qrppp_schedule.py Check that the above packet is moved to
/var/spool/packet/send/ and gets transmitted-- preferably by monitoring with another
radio. Note that Linux often drops packets on the first tx or two."""
    print "Hit Enter when done:",
    raw_input()

    print "...anything you still can't cope with is therefore your own problem..."

#
# ----------------------------------------------------------------------------
#
